package com.bit.book.model;

import com.bit.book.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private ResultCodeEnum code;
    private String errorMessage;
    private T data;

    public static <T> Result fail(String errorMessage){
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setErrorMessage(errorMessage);
        result.setData(null);
        return result;
    }

    public static <T> Result success(T data){
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }

    public static <T> Result unlogin(){
        Result result = new Result();
        result.setCode(ResultCodeEnum.UNLOGIN);
        result.setErrorMessage("用户未登录");
        result.setData(null);
        return result;
    }
}
